package com.woniuxy.sale.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: CHL  <br/>
 * @ToDo: 消息队列，交换机，绑定的配置类（路由模式）
 * Date: 2022/4/25:19:15  <br/>
 * Description:
 */
@Configuration
public class RabbitMQConfiguration {
    //创建一个消息队列
    @Bean
    public Queue packingListQueue(){
        return new Queue("packingList_queue");
    }
    @Bean
    public Queue packingMsgQueue(){
        return new Queue("packingMsg_queue");
    }

    @Bean
    //创建一个交换机
    public DirectExchange directExchange(){
        return new DirectExchange("direct_exchange_packing");
    }

    //绑定    这里面的参数名必须对应上，不然在spring容器中找不到这个对象
    @Bean
    public Binding bindingPackingListQueueToDirectExchange(DirectExchange directExchange,Queue packingListQueue){
        return BindingBuilder.bind(packingListQueue).to(directExchange).with("packingList");
    }
    @Bean
    public Binding bindingPackingMsgQueueToDirectExchange(DirectExchange directExchange,Queue packingMsgQueue){
        return BindingBuilder.bind(packingMsgQueue).to(directExchange).with("packingMsg");
    }



}
